import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';


class NewsContent extends StatefulWidget {
  
  Map arguments;
  NewsContent({Key key, this.arguments}) : super(key: key);

  @override
  _NewsContentState createState() => _NewsContentState(this.arguments);
}

class _NewsContentState extends State<NewsContent> {

  bool _flag = true;
  Map arguments;
  _NewsContentState(this.arguments);

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('新闻详情') 
      ), 
      body: Column(
        children: <Widget>[
          this._flag? _getMoreWidget() : Text(''),
          Expanded(
            child: InAppWebView(
              initialUrl: "http://www.phonegap100.com/newscontent.php?aid=${this.arguments['aid']}", 
              // initialUrl: "https://www.baidu.com",
              onProgressChanged: (InAppWebViewController controller, int progress){
                print(progress / 100);
                if(progress / 100 > 0.99) {
                  setState(() {
                    this._flag = false;
                  });
                }
                
              },
            )  
          )
        ],
      )
    );
  }

  //加载中的圈圈
  Widget _getMoreWidget(){
    return Center(
      child: Padding(
        padding: EdgeInsets.all(10),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            CircularProgressIndicator(
              strokeWidth: 1, 
            ),
            Text(
              '加载中...',
              style: TextStyle(fontSize:16)
            )
          ], 
        ),
      ),
    ); 
  }
}